package com.zfei.gfb.api.domain;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * @author fgh
 */
@ApiModel("事件定义：事件作者对事件目标做了什么，比如村民A对房源id=xxxx做了收藏动作")
public class TalkEvent implements Serializable, Comparable<TalkEvent> {

    /**
     * like event content
     */
    public static final String CLAIM = "{\"text\":\"claim\"}";
    public static final String BROWSE = "{\"text\":\"browse\"}";
    public static final String COLLECT = "{\"text\":\"collect\"}";
    /**
     * 资源内容
     */
    @ApiModelProperty(value = "事件内容,做了什么", notes = "做了什么")
    private String content;
    /**
     * 事件作者
     * 用户id，说吧吧主打赏特例（talkId）
     */
    @ApiModelProperty("事件作者")
    private String account;
    /**
     * 事件ID
     */
    @ApiModelProperty(value = "事件id", notes = "事件表主键")
    private String eventId;
    /**
     * 事件时间
     */
    @ApiModelProperty("事件时间")
    private Long eventTime;
    /**
     * 事件级别
     */
    @ApiModelProperty("事件类别,103=收藏房源;102=菜地认领")
    private Integer eventTier;
    /**
     * 事件类型
     */
    private Integer eventType;
    /**
     * 事件权限
     */
    private Integer privilege;
    /**
     * 事件来源
     */
    private String source;
    /**
     * 相关事件
     */
    private String correlation;
    /**
     * 父事件
     */
    @ApiModelProperty(value = "事件目标用户,事件操作的对象，比如被收藏的房源id", notes = "事件操作的对象，比如被收藏的房源id")
    private String parent;
    /**
     * 源事件
     */
    private String origin;

    /**
     * 扩展信息
     */
    private String ext;
    /**
     * 删除时间
     */
    @ApiModelProperty("删除时间")
    private Long deleteTime;

    /**
     * 创建时间
     */
    private Long createTime;
    /**
     * 更新时间
     */
    private Long updateTime;

    private Update update;
    private String spam;

    @ApiModelProperty("事件日期")
    private String date;

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public static int compare(TalkEvent x, TalkEvent y) {
        int value = Long.compare(x.getEventTime(), y.getEventTime());
        if (value == 0) {
            return x.getEventId().compareTo(y.getEventId());
        }
        return value;
    }

    /**
     * 关联话题ID列表
     */
    private List<String> topicIds;

    public String getSpam() {
        return spam;
    }

    public void setSpam(String spam) {
        this.spam = spam;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getEventId() {
        return eventId;
    }

    public void setEventId(String eventId) {
        this.eventId = eventId;
    }

    public Long getEventTime() {
        return eventTime;
    }

    public void setEventTime(Long eventTime) {
        this.eventTime = eventTime;
    }

    public Integer getEventTier() {
        return eventTier;
    }

    public void setEventTier(Integer eventTier) {
        this.eventTier = eventTier;
    }

    public Integer getEventType() {
        return eventType;
    }

    public void setEventType(Integer eventType) {
        this.eventType = eventType;
    }

    public Integer getPrivilege() {
        return privilege;
    }

    public void setPrivilege(Integer privilege) {
        this.privilege = privilege;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getCorrelation() {
        return correlation;
    }

    public void setCorrelation(String correlation) {
        this.correlation = correlation;
    }

    public String getParent() {
        return parent;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }

    public String getExt() {
        return ext;
    }

    public void setExt(String ext) {
        this.ext = ext;
    }

    public Long getDeleteTime() {
        return deleteTime;
    }

    public void setDeleteTime(Long deleteTime) {
        this.deleteTime = deleteTime;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    public Update getUpdate() {
        return update;
    }

    public void setUpdate(Update update) {
        this.update = update;
    }

    public List<String> getTopicIds() {
        return topicIds;
    }

    public void setTopicIds(List<String> topicIds) {
        this.topicIds = topicIds;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TalkEvent talkEvent = (TalkEvent) o;
        return Objects.equals(eventTier, talkEvent.eventTier) && Objects.equals(account, talkEvent.account) && Objects.equals(parent, talkEvent.parent);
    }

    @Override
    public int hashCode() {
        return Objects.hash(eventTier, account, parent);
    }

    public EventTuple tuple() {
        EventTuple tuple = new EventTuple();
        tuple.setEventId(this.getEventId());
        tuple.setEventTime(this.getEventTime());
        return tuple;
    }

    // Transient Fields

    @Override
    public int compareTo(TalkEvent o) {
        return compare(this, o);
    }

    public boolean isDeleted() {
        return this.getDeleteTime() != null && this.getDeleteTime() != 0;
    }

    public boolean notDeleted() {
        return !isDeleted();
    }

    public void introspect() {
        setDate(DateUtil.date(getEventTime()).toDateStr());
    }

    @Override
    public String toString() {
        return "TalkEvent{" +
                "eventId='" + eventId + '\'' +
                '}';
    }


}
